package com.ys.controller.api.outer;

import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentials;
import com.amazon.SellingPartnerAPIAA.AWSAuthenticationCredentialsProvider;
import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials;
import com.amazon.SellingPartnerAPIAA.LWAException;
import com.bo.sellingpartnerapi.Definitionsproducttypes20200901.api.DefinitionsApi;
import com.bo.sellingpartnerapi.Definitionsproducttypes20200901.model.ProductTypeDefinition;
import com.bo.sellingpartnerapi.Definitionsproducttypes20200901.model.ProductTypeList;
import com.bo.sellingpartnerapi.Feeds20210630.model.Feed;
import com.bo.sellingpartnerapi.Listingsitems20210801.api.ListingsApi;
import com.bo.sellingpartnerapi.Listingsitems20210801.model.*;
import com.bo.sellingpartnerapi.Reports20210630.api.ReportsApi;
import com.bo.sellingpartnerapi.Reports20210630.model.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.ys.config.MyConfig;
import com.ys.entity.base.TbPlatform;
import com.ys.entity.business.TbAmazonCategory;
import com.ys.entity.business.TpAmazonShop;
import com.ys.mapper.business.TbAmazonCategoryMapper;
import com.ys.util.AESUtil;
import com.ys.util.dhecp.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;

/**
 * @Author: fxz
 * @CreateTime: 2024-09-14
 * @Description: lisitng api逻辑
 * @Version: 1.0
 */
@Controller
@RequestMapping("/api/outer/demoFXZlisitng")
public class ApiOuterDemoFXZLisitngController {


    @Autowired
    private TbAmazonCategoryMapper tbAmazonCategoryMapper;

    /**
     * listing刊登第一步 类目结构信息：通过Report API的GET_XML_BROWSE_TREE_DATA
     */
    @RequestMapping("/test8")
    @ResponseBody
    public void test3() {
        Map<String, Object> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where("A.id = 4144")
                .queryFirstMap();
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(tpAmazonShopList));

        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null){
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<String> marketplaceIdList =  new ArrayList<>();
        if(!StringUtils.isEmpty(jsonObject.get("marketplaceId").toString())) {
            String marketplaceIds = jsonObject.get("marketplaceId").toString();
            String[] marketplaceIdArray = marketplaceIds.split(",");
            marketplaceIdList = new ArrayList<>(Arrays.asList(marketplaceIdArray));
        }

        CreateReportSpecification body = new CreateReportSpecification();
        body.setReportType("GET_XML_BROWSE_TREE_DATA");
        body.setMarketplaceIds(marketplaceIdList);
        ReportOptions reportOptions = new ReportOptions();
        reportOptions.put("period","P2D");
        body.setReportOptions(reportOptions);
        CreateReportResponse reportResponse =  null;
        try {
            AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
                    .accessKeyId(MyConfig.getAmazonAwsAccessKey())
                    .secretKey(MyConfig.getAmazonAwsAccessSecret())
                    .region(jsonObject.get("awsRegion").toString())
                    .build();
            AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
                    .roleArn(MyConfig.getAmazonRoleArn())
                    .roleSessionName(MyConfig.getAmazonRoleSessionName())
                    .build();
            LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                    .clientId(MyConfig.getAmazonLwaClientKey())
                    .clientSecret(encryptSecret)
                    .refreshToken(jsonObject.get("refreshToken").toString())
                    .endpoint(MyConfig.getAmazonLwaEndpoint())
                    .build();

            ReportsApi reportsApi = new ReportsApi.Builder()
                    .awsAuthenticationCredentials(awsAuthenticationCredentials)
                    .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                    .awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
                    .endpoint(jsonObject.get("amazonServiceUrl").toString())
                    .build();

            reportResponse = reportsApi.createReport(body);
            if (reportResponse != null) {
                String reportId = reportResponse.getReportId();
                String reportDocumentId = "";
                Report report = null;
                Report.ProcessingStatusEnum processingStatus = null;
                while (true) {
                    report = reportsApi.getReport(reportId);
                    processingStatus = report.getProcessingStatus();
                    if (Feed.ProcessingStatusEnum.DONE.getValue().equals(processingStatus.getValue())
                            || Feed.ProcessingStatusEnum.CANCELLED.getValue().equals(processingStatus.getValue())
                            || Feed.ProcessingStatusEnum.FATAL.getValue().equals(processingStatus.getValue())) {
                        if (report != null) {
                            reportDocumentId = report.getReportDocumentId();
                        }
                        break;
                    } else {
                        Thread.sleep(10000L);
                        continue;
                    }
                }
                if (report != null){
                    if (!StringUtils.isEmpty(reportDocumentId)) {
                        ReportDocument reportDocument = reportsApi.getReportDocument(reportDocumentId);
                        if (reportDocument != null) {
                            String compressionAlgorithm = (reportDocument.getCompressionAlgorithm() == null ? "":reportDocument.getCompressionAlgorithm().toString());
                            OkHttpClient httpclient = new OkHttpClient();
                            httpclient.setConnectTimeout(30, TimeUnit.SECONDS);
                            httpclient.setReadTimeout(30, TimeUnit.SECONDS);
                            httpclient.setWriteTimeout(30, TimeUnit.SECONDS);
                            Request request = new Request.Builder()
                                    .url(reportDocument.getUrl())
                                    .get()
                                    .build();

                            Response httpResponse = httpclient.newCall(request).execute();
                            try (com.squareup.okhttp.ResponseBody responseBody = httpResponse.body()) {
                                MediaType mediaType = MediaType.parse(httpResponse.header("Content-Type"));
                                Charset charset = mediaType.charset();
                                Closeable closeThis = null;
                                try {
                                    InputStream inputStream = responseBody.byteStream();
                                    closeThis = inputStream;
                                    if ("GZIP".equals(compressionAlgorithm)) {
                                        closeThis = inputStream;
                                        inputStream = new GZIPInputStream(inputStream);
                                        byte[] zipBytes = ZipUtil.unGzip(inputStream);
                                        String filePath = MyConfig.getProfile() + "/amazonreport/salestraffic/"+"asdsad".replace("-", "");
                                        String gzOutPath =  filePath + "/salestraffic_report_" + jsonObject.get("id").toString();
                                        File gzOutFileObj= new File(gzOutPath);
                                        if(!gzOutFileObj.exists()){
                                            gzOutFileObj.mkdirs();
                                        }
                                        String gzFileNamePrefix = "salestraffic_report_" + jsonObject.get("id").toString();
                                        String fileName = gzFileNamePrefix +".xml";
                                        //将文件解压到gzOutPath目录中
                                        File gzOutFile = new File(gzOutPath + "/"+fileName);
                                        FileOutputStream fileOutputStream = new FileOutputStream(gzOutFile);
                                        fileOutputStream.write(zipBytes);
                                        fileOutputStream.close();
                                        File[] txtFileList = gzOutFileObj.listFiles();
                                        InputStream txtInputStream = null;
                                        StringBuffer txtStringBuffer = null;
                                        BufferedReader txtBufferedReader = null;
                                        if (txtFileList != null && txtFileList.length  > 0){
                                            for (File txtFileItem : txtFileList) {
                                                txtInputStream = new FileInputStream(txtFileItem);
                                                String txtLine; // 用来保存每行读取的内容
                                                txtStringBuffer = new StringBuffer();
                                                txtBufferedReader = new BufferedReader(new InputStreamReader(txtInputStream));
                                                txtLine = txtBufferedReader.readLine(); // 读取第一行
                                                while (txtLine != null) { // 如果 line 为空说明读完了
                                                    txtStringBuffer.append(txtLine); // 将读到的内容添加到 buffer 中
                                                    txtStringBuffer.append("\n"); // 添加换行符
                                                    txtLine = txtBufferedReader.readLine(); // 读取下一行
                                                }
                                                if(txtBufferedReader != null) txtBufferedReader.close();
                                                if(txtInputStream != null) txtInputStream.close();
                                                String txtContent = txtStringBuffer.toString();
                                                if (!StringUtils.isEmpty(txtContent)){
                                                    JSONObject jsonObjecttxtContent = JSON.parseObject(txtContent);
                                                    if (jsonObjecttxtContent != null){
                                                        JSONArray jsonArray = jsonObjecttxtContent.getJSONArray("salesAndTrafficByAsin");
                                                        if (jsonArray != null && jsonArray.size() > 0){
                                                            for(int i=0;i<jsonArray.size();i++) {
                                                                JSONObject itemJsonObj = jsonArray.getJSONObject(i);
                                                                itemJsonObj = itemJsonObj;
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                        }
                                    }
                                }catch (Exception ex){

                                }
                            }
                        }
                    }
                }
            }
        }catch (Exception e){

        }

    }



    /**
     * listing刊登第二步 获取类目Schema：通过Product Type Definitions的get Definitions Product Type获取
     */
    @RequestMapping("/test5")
    @ResponseBody
    public void test5() {
        Map<String, Object> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where("A.id = 2735")
                .queryFirstMap();
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(tpAmazonShopList));

        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null){
            return;
        }

        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
                .accessKeyId(MyConfig.getAmazonAwsAccessKey())
                .secretKey(MyConfig.getAmazonAwsAccessSecret())
                .region(jsonObject.get("awsRegion").toString())
                .build();

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        DefinitionsApi api = new DefinitionsApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .awsAuthenticationCredentials(awsAuthenticationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();

        List<String> marketplaceIdList = new ArrayList<>();
        if (!StringUtils.isEmpty(jsonObject.get("marketplaceId").toString())) {
            String marketplaceIds = jsonObject.get("marketplaceId").toString();
            String[] marketplaceIdArray = marketplaceIds.split(",");
            marketplaceIdList = new ArrayList<>(Arrays.asList(marketplaceIdArray));
        }
        List<String> keywords = new ArrayList<>();
//        keywords.add("INFANT TODDLER CAR SEAT");
//        keywords.add("Reading Glass Accessories");
        String locale = "en_GB";
        String searchLocale = "en_GB";
            ProductTypeList productTypeList = null;
            try {
                //该功能直接获取该有的类型
//                productTypeList = api.searchDefinitionsProductTypes(marketplaceIdList, keywords);
//                productTypeList = productTypeList;

//                String productType = "PET_SUPPLIES";
//                String productType = "TOILET_PAPER";
                String productType = "MICROPHONE";
                //根据类型获取schema
                ProductTypeDefinition definitionsProductType = api.getDefinitionsProductType(productType, marketplaceIdList, null, null, null, null, null);
                definitionsProductType = definitionsProductType;
            } catch (com.bo.sellingpartnerapi.Definitionsproducttypes20200901.invoker.ApiException e) {
                e.printStackTrace();
            }
    }

    @RequestMapping("/test411")
    @ResponseBody
    public void test411() {
        Map<String, Object> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.SellerId = A.SellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where("A.ShopName = '斯鹭-GB' ")
                .queryFirstMap();
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(tpAmazonShopList));

        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null){
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
                .accessKeyId(MyConfig.getAmazonAwsAccessKey())
                .secretKey(MyConfig.getAmazonAwsAccessSecret())
                .region(jsonObject.get("awsRegion").toString())
                .build();

        AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
                .roleArn(MyConfig.getAmazonRoleArn())
                .roleSessionName(MyConfig.getAmazonRoleSessionName())
                .build();
        com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        List<String> marketplaceIdList =  new ArrayList<>();
        if(!StringUtils.isEmpty(jsonObject.get("marketplaceId").toString())) {
            String marketplaceIds = jsonObject.get("marketplaceId").toString();
            String[] marketplaceIdArray = marketplaceIds.split(",");
            marketplaceIdList = new ArrayList<>(Arrays.asList(marketplaceIdArray));
        }
        ListingsApi listingsApi = new ListingsApi.Builder()
                .awsAuthenticationCredentials(awsAuthenticationCredentials)
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        Gson gson = new Gson();
        JsonElement element = gson.fromJson(
                "{\n" +
                "       \"item_name\": [\n" +
                "        {\n" +
                "            \"value\": \"3 Pack Cat Litter Scoop Plastic Cat Litter Shovel Pet Clean Shovel for Cats\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\",\n" +
                "           \"language_tag\": \"en_GB\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"brand\": [\n" +
                "        {\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"value\": \"SICAILU\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                " \t\"recommended_browse_nodes\": [\n" +
                "        {\n" +
                "            \"value\": \"471341031\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "          \n" +
                "        }\n" +
                "    ],\n" +
                " \"model_number\": [\n" +
                "        { \n" +
                "            \"value\": \"SILULCM0001\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"model_name\": [\n" +
                "        {\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"value\": \"SILULCM0001\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                " \"manufacturer\": [\n" +
                "        {\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"value\": \"SILULCM\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "   \"product_description\": [\n" +
                "        {\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"value\": \"3 Pack Cat Litter Scoop Plastic Cat Litter Shovel Pet Clean Shovel for Cats\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"bullet_point\": [\n" +
                "        {\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"value\": \"【Avoid Dirty Hands】After purchasing this cat litter scoop, you can easily clean the dustbin to avoid touching dirty garbage, which will be more clean and sanitary and bring you great convenience.\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        },\n" +
                "{\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"value\": \"【Unique Design】This cleaning shovel has wide grooves and comfortable to hold. It is a perfect litter spoon, which can be used to quickly scoop up lumps and screen clean garbage, saving time for cleaning litter.\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"color\": [\n" +
                "        {\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"value\": \"B-hanging Eucalyptus Wall Decor Large\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "\n" +
                "    \"country_of_origin\": [\n" +
                "        {\n" +
                "            \"value\": \"CN\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "\n" +
                "    \"batteries_required\": [\n" +
                "        {\n" +
                "            \"value\": false,\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"item_package_weight\": [\n" +
                "        {\n" +
                "            \"value\": 92,\n" +
                "             \"unit\":\"grams\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ], \n" +
                "    \"unit_count\": [\n" +
                "        {\n" +
                "            \"value\": 3,\n" +
                "             \"type\":{\n" +
                "             \t\t\"language_tag\": \"en_US\",\n" +
                "               \t\t\"value\":\"count\"\n" +
                "             },\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "         \"is_expiration_dated_product\": [\n" +
                "        {\n" +
                "            \"value\": false,\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ], \n" +
                "         \"power_plug_type\": [\n" +
                "        {\n" +
                "            \"value\": \"no_plug\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ], \n" +
                "    \"condition_type\": [\n" +
                "        {\n" +
                "            \"value\": \"new_new\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "   \"item_package_dimensions\": [\n" +
                "        {\n" +
                "            \"height\": {\n" +
                "                \"unit\": \"centimeters\",\n" +
                "                \"value\": 4\n" +
                "            },\n" +
                "            \"length\": {\n" +
                "                \"unit\": \"centimeters\",\n" +
                "                \"value\": 21\n" +
                "            },\n" +
                "            \"width\": {\n" +
                "                \"unit\": \"centimeters\",\n" +
                "                \"value\": 12\n" +
                "            },\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"number_of_boxes\": [\n" +
                "        {\n" +
                "            \"value\": 1,\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"fulfillment_availability\": [\n" +
                "        {\n" +
                "            \"fulfillment_channel_code\": \"AMAZON_EU\"            \n" +
                "        }\n" +
                "    ],\n" +
                " \"contains_food_or_beverage\": [\n" +
                "        {\n" +
                "            \"value\": false,\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                " \"contains_liquid_contents\": [\n" +
                "        {\n" +
                "            \"value\": false,\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                " \"warranty_description\": [\n" +
                "        {\n" +
                "            \"value\": \"2 year manufacturer\",\n" +
                "             \"language_tag\": \"en_US\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                " \"merchant_suggested_asin\": [\n" +
                "        {\n" +
                "            \"value\": \"B0BPRQ7YP5\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"specific_uses_for_product\": [\n" +
                "        {\n" +
                "            \"value\": \"Indoor\",\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "   \"included_components\": [\n" +
                "        {\n" +
                "            \"value\": \"Camera Body, Battery Pack\",\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                " \"is_oem_authorized\": [\n" +
                "        {\n" +
                "            \"value\": false,\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                " \"directions\": [\n" +
                "        {\n" +
                "            \"value\": \"3 Pack Cat Litter Scoop Plastic Cat Litter Shovel Pet Clean Shovel for Cats\",\n" +
                "            \"language_tag\": \"en_US\",\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"purchasable_offer\": [\n" +
                "        {\n" +
                "            \"currency\": \"GBP\",\n" +
                "            \"our_price\":[{\n" +
                "                            \"schedule\":\n" +
                "                               [{\"value_with_tax\" : 77.7}]    \n" +
                "                        }] , \n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                "      \"list_price\": [\n" +
                "        {\n" +
                "            \"currency\": \"GBP\",\n" +
                "            \"value_with_tax\": 69,\n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ],\n" +
                " \"supplier_declared_dg_hz_regulation\": [\n" +
                "        {\n" +
                "            \"value\": \"not_applicable\",  \n" +
                "            \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                "        }\n" +
                "    ]\n" +
                "}\n" +
                "                                                                               "
                , JsonElement.class);

        //TODO 对应图片只能通过亚马逊s3中获取图片处理
        ListingsItemPutRequest listingsItemPutRequest = new ListingsItemPutRequest();
        listingsItemPutRequest.setProductType("PET_SUPPLIES");
        listingsItemPutRequest.setAttributes(element);
        try {
            ListingsItemSubmissionResponse listingsItemSubmissionResponse = listingsApi.putListingsItem(jsonObject.get("sellerId").toString(),
                    "FXZ-6JFR-38OK1",marketplaceIdList,listingsItemPutRequest,"en_US");
            listingsItemSubmissionResponse = listingsItemSubmissionResponse;
//			class ListingsItemSubmissionResponse {
//				sku: FXZ-6JFR-38OH
//				status: ACCEPTED
//				submissionId: 59ec7dd8f3d64205898bd2ebe8b6ebd3
//				issues: []
//			}
//			class ListingsItemSubmissionResponse {
//				sku: FXZ-6JFR-38OQ
//				status: ACCEPTED
//				submissionId: c5d7bda2fcb345f6922ab8f7b388fc46
//				issues: []
//			}

//			List<String> listIncludedData = new ArrayList<>();
//			listIncludedData.add("issues");
//			listIncludedData.add("attributes");
//			listIncludedData.add("summaries");
//			listIncludedData.add("offers");
//			listIncludedData.add("fulfillmentAvailability");
//			String listIssueLocale = "en_US";
//			Item listingsItem = null;
//			listingsItem = listingsApi.getListingsItem(
//					jsonObject.get("sellerId").toString(),"FXZ-6JFR-38OB" ,
//					marketplaceIdList, listIssueLocale, listIncludedData);
//			listingsItem = listingsItem;
        } catch (com.bo.sellingpartnerapi.Listingsitems20210801.invoker.ApiException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/test4112")
    @ResponseBody
    public void test4112() {
        Map<String, Object> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.SellerId = A.SellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where("A.id = 2735 ")
                .queryFirstMap();
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(tpAmazonShopList));

        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null){
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
                .accessKeyId(MyConfig.getAmazonAwsAccessKey())
                .secretKey(MyConfig.getAmazonAwsAccessSecret())
                .region(jsonObject.get("awsRegion").toString())
                .build();

        AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
                .roleArn(MyConfig.getAmazonRoleArn())
                .roleSessionName(MyConfig.getAmazonRoleSessionName())
                .build();
        com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        List<String> marketplaceIdList =  new ArrayList<>();
        if(!StringUtils.isEmpty(jsonObject.get("marketplaceId").toString())) {
            String marketplaceIds = jsonObject.get("marketplaceId").toString();
            String[] marketplaceIdArray = marketplaceIds.split(",");
            marketplaceIdList = new ArrayList<>(Arrays.asList(marketplaceIdArray));
        }
        ListingsApi listingsApi = new ListingsApi.Builder()
                .awsAuthenticationCredentials(awsAuthenticationCredentials)
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        Gson gson = new Gson();
        JsonElement element = gson.fromJson(
                "  {\n" +
                        "  \"brand\": [\n" +
                        "    {\n" +
                        "      \"language_tag\": \"en_GB\",\n" +
                        "      \"value\": \"yimeizhiguang\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"bullet_point\": [\n" +
                        "    {\n" +
                        "      \"language_tag\": \"en_GB\",\n" +
                        "      \"value\": \"Mini Lapel Mic Wired Lavalier Microphone Smartphone Microphone Studio Quality Lapel Mic Hands-Free Recording Microphone Condenser Lav Mic for YouTube Clip-on Mic for Voiceover Professional ASMR Microphone\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"country_of_origin\": [\n" +
                        "    {\n" +
                        "      \"value\": \"CN\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"item_name\": [\n" +
                        "    {\n" +
                        "      \"value\": \"Lavalier Microphone Clip-on Omnidirectional Condenser Mic with 3.5mm Jack for iPhone, PC, Laptop, DSLR Camera – Perfect for Podcast, Interview, ASMR & Voice Recording – Enhanced Noise Reduction\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\",\n" +
                        "      \"language_tag\": \"en_GB\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"product_description\": [\n" +
                        "    {\n" +
                        "      \"language_tag\": \"en_GB\",\n" +
                        "      \"value\": \"【Crystal-Clear Studio Quality Sound】 Elevate your recordings with this Mini Lapel Mic, featuring a professional omnidirectional condenser for crisp, noise-free audio. Perfect for hands-free recording microphone use in podcasts, interviews, YouTube videos, and ASMR.\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"recommended_browse_nodes\": [\n" +
                        "    {\n" +
                        "      \"value\": \"407788031\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"supplier_declared_dg_hz_regulation\": [\n" +
                        "    {\n" +
                        "      \"value\": \"not_applicable\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"batteries_required\": [\n" +
                        "    {\n" +
                        "      \"value\": false,\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"item_package_dimensions\": [\n" +
                        "    {\n" +
                        "      \"height\": {\n" +
                        "        \"unit\": \"centimeters\",\n" +
                        "        \"value\": 0.5\n" +
                        "      },\n" +
                        "      \"length\": {\n" +
                        "        \"unit\": \"centimeters\",\n" +
                        "        \"value\": 15\n" +
                        "      },\n" +
                        "      \"width\": {\n" +
                        "        \"unit\": \"centimeters\",\n" +
                        "        \"value\": 20\n" +
                        "      },\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"list_price\": [\n" +
                        "    {\n" +
                        "      \"currency\": \"GBP\",\n" +
                        "      \"value_with_tax\": 15.99,\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"item_package_weight\": [\n" +
                        "    {\n" +
                        "      \"unit\": \"grams\",\n" +
                        "      \"value\": 30,\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"manufacturer\": [\n" +
                        "    {\n" +
                        "      \"value\": \"yimeizhiguang\",\n" +
                        "      \"language_tag\": \"en_GB\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"supplier_declared_has_product_identifier_exemption\": [\n" +
                        "    {\n" +
                        "      \"value\": true\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"part_number\": [\n" +
                        "    {\n" +
                        "      \"value\": \"yimeizhiguang25041102\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"number_of_items\": [\n" +
                        "    {\n" +
                        "      \"value\": 1,\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"fulfillment_availability\": [\n" +
                        "    {\n" +
                        "      \"fulfillment_channel_code\": \"AMAZON_EU\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"condition_type\": [\n" +
                        "    {\n" +
                        "      \"value\": \"new_new\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"purchasable_offer\": [\n" +
                        "    {\n" +
                        "      \"currency\": \"GBP\",\n" +
                        "      \"our_price\": [\n" +
                        "        {\n" +
                        "          \"schedule\": [\n" +
                        "            {\n" +
                        "              \"value_with_tax\": 15.99\n" +
                        "            }\n" +
                        "          ]\n" +
                        "        }\n" +
                        "      ]\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"main_product_image_locator\": [\n" +
                        "    {\n" +
                        "      \"media_location\": \"https://file.mini-ease.com/upload/nomodule/202504/11/175932882.jpg\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"other_product_image_locator_1\": [\n" +
                        "    {\n" +
                        "      \"media_location\": \"https://file.mini-ease.com/upload/nomodule/202504/11/175946099.jpg\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"other_product_image_locator_2\": [\n" +
                        "    {\n" +
                        "      \"media_location\": \"https://file.mini-ease.com/upload/nomodule/202504/11/175954394.jpg\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"other_product_image_locator_3\": [\n" +
                        "    {\n" +
                        "      \"media_location\": \"https://file.mini-ease.com/upload/nomodule/202504/11/180017548.jpg\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"other_product_image_locator_4\": [\n" +
                        "    {\n" +
                        "      \"media_location\": \"https://file.mini-ease.com/upload/nomodule/202504/11/180039467.jpg\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"other_product_image_locator_5\": [\n" +
                        "    {\n" +
                        "      \"media_location\": \"https://file.mini-ease.com/upload/nomodule/202504/11/180051082.jpg\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"other_product_image_locator_6\": [\n" +
                        "    {\n" +
                        "      \"media_location\": \"https://file.mini-ease.com/upload/nomodule/202504/11/180103364.jpg\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"other_product_image_locator_7\": [\n" +
                        "    {\n" +
                        "      \"media_location\": \"https://file.mini-ease.com/upload/nomodule/202504/11/180114079.jpg\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"warranty_description\": [\n" +
                        "    {\n" +
                        "      \"value\": \"2 year manufacturer\",\n" +
                        "      \"language_tag\": \"en_GB\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"included_components\": [\n" +
                        "    {\n" +
                        "      \"value\": \"Camera Body, Battery Pack\",\n" +
                        "      \"language_tag\": \"en_GB\",\n" +
                        "      \"marketplace_id\": \"A1F83G8C2ARO7P\"\n" +
                        "    }\n" +
                        "  ],\n" +
                        "  \"gdpr_risk\": [\n" +
                        "    {\n" +
                        "      \"value\": \"no_electronic_information_stored\"\n" +
                        "    }\n" +
                        "  ]\n" +
                        "}\n" +
                        "\n" +
                        "\n" +
                        "\n                                                          "
                , JsonElement.class);

        ListingsItemPutRequest listingsItemPutRequest = new ListingsItemPutRequest();
        listingsItemPutRequest.setProductType("MICROPHONE");
        listingsItemPutRequest.setAttributes(element);
        try {
            ListingsItemSubmissionResponse listingsItemSubmissionResponse = listingsApi.putListingsItem(jsonObject.get("sellerId").toString(),
                    "yimeizhiguang004",marketplaceIdList,listingsItemPutRequest,"en_GB");
            listingsItemSubmissionResponse = listingsItemSubmissionResponse;
            System.out.println(JSONArray.toJSONString(listingsItemSubmissionResponse));
//            {"issues":[],"sku":"FXZ-6JFR-38OK1","status":"ACCEPTED","submissionId":"0e80fdad9b734f208153e3c7c5d22a04"}
//			class ListingsItemSubmissionResponse {
//				sku: FXZ-6JFR-38OH
//				status: ACCEPTED
//				submissionId: 59ec7dd8f3d64205898bd2ebe8b6ebd3
//				issues: []
//			}
//			class ListingsItemSubmissionResponse {
//				sku: FXZ-6JFR-38OQ
//				status: ACCEPTED
//				submissionId: c5d7bda2fcb345f6922ab8f7b388fc46
//				issues: []
//			}

        } catch (com.bo.sellingpartnerapi.Listingsitems20210801.invoker.ApiException e) {
            e.printStackTrace();
        }
    }


    @RequestMapping("/test4111")
    @ResponseBody
    public void test4111() {
        Map<String, Object> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.SellerId = A.SellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where("A.id = 2735 ")
                .queryFirstMap();
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(tpAmazonShopList));

        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null){
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
                .accessKeyId(MyConfig.getAmazonAwsAccessKey())
                .secretKey(MyConfig.getAmazonAwsAccessSecret())
                .region(jsonObject.get("awsRegion").toString())
                .build();

        AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
                .roleArn(MyConfig.getAmazonRoleArn())
                .roleSessionName(MyConfig.getAmazonRoleSessionName())
                .build();
        com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        List<String> marketplaceIdList =  new ArrayList<>();
        if(!StringUtils.isEmpty(jsonObject.get("marketplaceId").toString())) {
            String marketplaceIds = jsonObject.get("marketplaceId").toString();
            String[] marketplaceIdArray = marketplaceIds.split(",");
            marketplaceIdList = new ArrayList<>(Arrays.asList(marketplaceIdArray));
        }
        ListingsApi listingsApi = new ListingsApi.Builder()
                .awsAuthenticationCredentials(awsAuthenticationCredentials)
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
			List<String> listIncludedData = new ArrayList<>();
			listIncludedData.add("issues");
			listIncludedData.add("attributes");
			listIncludedData.add("summaries");
			listIncludedData.add("offers");
			listIncludedData.add("fulfillmentAvailability");
			String listIssueLocale = "en_US";
			Item listingsItem = null;
			listingsItem = listingsApi.getListingsItem(
					jsonObject.get("sellerId").toString(),"yimeizhiguang004" ,
					marketplaceIdList, listIssueLocale, listIncludedData);
			listingsItem = listingsItem;
            System.out.println(JSONArray.toJSONString(listingsItem));
        } catch (com.bo.sellingpartnerapi.Listingsitems20210801.invoker.ApiException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/test41111")
    @ResponseBody
    public void test41111() {
        Map<String, Object> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.SellerId = A.SellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where("A.id = 6802 ")
                .queryFirstMap();
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(tpAmazonShopList));

        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null){
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
                .accessKeyId(MyConfig.getAmazonAwsAccessKey())
                .secretKey(MyConfig.getAmazonAwsAccessSecret())
                .region(jsonObject.get("awsRegion").toString())
                .build();

        AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
                .roleArn(MyConfig.getAmazonRoleArn())
                .roleSessionName(MyConfig.getAmazonRoleSessionName())
                .build();
        com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        List<String> marketplaceIdList =  new ArrayList<>();
        if(!StringUtils.isEmpty(jsonObject.get("marketplaceId").toString())) {
            String marketplaceIds = jsonObject.get("marketplaceId").toString();
            String[] marketplaceIdArray = marketplaceIds.split(",");
            marketplaceIdList = new ArrayList<>(Arrays.asList(marketplaceIdArray));
        }
        ListingsApi listingsApi = new ListingsApi.Builder()
                .awsAuthenticationCredentials(awsAuthenticationCredentials)
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();

        ListingsItemPatchRequest listingsItemPatchRequest = new ListingsItemPatchRequest();
        listingsItemPatchRequest.setProductType("TOILET_PAPER");
        List<PatchOperation> patches = new ArrayList<>();
        PatchOperation  patchOperation = new PatchOperation();
        patchOperation.setOp(PatchOperation.OpEnum.REPLACE);
//        patchOperation.setPath("/attributes/main_product_image_locator");//主图1
//        patchOperation.setPath("/attributes/fulfillment_availability");//自发货或者亚马逊
//        patchOperation.setPath("/attributes/list_price");//零售价(含税价目表)
        patchOperation.setPath("/attributes/purchasable_offer");//产品报价
        List<Object> value = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
//        map.put("media_location","https://file.mini-ease.com/upload/nomodule/202504/10/194534584.jpg");//main_product_image_locator
//        map.put("fulfillment_channel_code","AMAZON_EU");//fulfillment_availability
//        map.put("currency","GBP");//list_price
//        map.put("value_with_tax",22);//list_price
        map.put("currency","GBP");//purchasable_offer
        List<Object> our_priceValue = new ArrayList<>();
        Map<String,Object> our_priceMap = new HashMap<>();
        List<Object> scheduleList = new ArrayList<>();
        Map<String,Object> scheduleMap = new HashMap<>();
        scheduleMap.put("value_with_tax",9.99);
        scheduleList.add(scheduleMap);
        our_priceMap.put("schedule",scheduleList);
        our_priceValue.add(our_priceMap);
        map.put("our_price",our_priceValue);//purchasable_offer

//        List<Object> our_priceValue1 = new ArrayList<>();
//        Map<String,Object> our_priceMap1 = new HashMap<>();
//        List<Object> scheduleList1 = new ArrayList<>();
//        Map<String,Object> scheduleMap1 = new HashMap<>();
//        scheduleMap1.put("value_with_tax",55);
//        scheduleList1.add(scheduleMap1);
//        our_priceMap1.put("schedule",scheduleList);
//        our_priceValue1.add(our_priceMap);
//
//        map.put("map_price",our_priceValue1);//purchasable_offer
//        map.put("audience","B2C");//purchasable_offer
        value.add(map);
        patchOperation.setValue(value);
        patches.add(patchOperation);
        listingsItemPatchRequest.setPatches(patches);
        try {
//            ListingsItemSubmissionResponse listingsItemSubmissionResponse = listingsApi.patchListingsItem(jsonObject.get("sellerId").toString(),
////                    "XRDP200426021-01",marketplaceIdList,listingsItemPatchRequest,"en_GB");
//                    "FXZ-6JFR-38OK1",marketplaceIdList,listingsItemPatchRequest,"en_GB");
//            listingsItemSubmissionResponse = listingsItemSubmissionResponse;
//            System.out.println(JSONArray.toJSONString(listingsItemSubmissionResponse));


            List<String> listIncludedData = new ArrayList<>();
            listIncludedData.add("issues");
            listIncludedData.add("attributes");
            listIncludedData.add("summaries");
            listIncludedData.add("offers");
            listIncludedData.add("fulfillmentAvailability");
            String listIssueLocale = "en_GB";
            Item listingsItem = null;
            listingsItem = listingsApi.getListingsItem(
//                    jsonObject.get("sellerId").toString(),"XRDP200426021-01" ,
                    jsonObject.get("sellerId").toString(),"FXZ-6JFR-38OK1" ,
                    marketplaceIdList, listIssueLocale, listIncludedData);
            listingsItem = listingsItem;
        } catch (com.bo.sellingpartnerapi.Listingsitems20210801.invoker.ApiException e) {
            e.printStackTrace();
        }
    }


    @RequestMapping("/test511")
    @ResponseBody
    public void test511() {
        Map<String, Object> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.SellerId = A.SellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where("A.id = 2735 ")
                .queryFirstMap();
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(tpAmazonShopList));

        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
                .accessKeyId(MyConfig.getAmazonAwsAccessKey())
                .secretKey(MyConfig.getAmazonAwsAccessSecret())
                .region(jsonObject.get("awsRegion").toString())
                .build();

        AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
                .roleArn(MyConfig.getAmazonRoleArn())
                .roleSessionName(MyConfig.getAmazonRoleSessionName())
                .build();
        com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        List<String> marketplaceIdList = new ArrayList<>();
        if (!StringUtils.isEmpty(jsonObject.get("marketplaceId").toString())) {
            String marketplaceIds = jsonObject.get("marketplaceId").toString();
            String[] marketplaceIdArray = marketplaceIds.split(",");
            marketplaceIdList = new ArrayList<>(Arrays.asList(marketplaceIdArray));
        }
        ListingsApi listingsApi = new ListingsApi.Builder()
                .awsAuthenticationCredentials(awsAuthenticationCredentials)
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();


        try {
            ListingsItemSubmissionResponse listingsItemSubmissionResponse = listingsApi.deleteListingsItem(jsonObject.get("sellerId").toString(),
                    "yimeizhiguang001", marketplaceIdList, "en_US");
            listingsItemSubmissionResponse = listingsItemSubmissionResponse;
            //TODO 删除也不是及时删除 是需要通过get接口获取是否删除成功
        } catch (com.bo.sellingpartnerapi.Listingsitems20210801.invoker.ApiException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/test611")
    @ResponseBody
    public void test611() {

//        try {
//            // 1. 创建 StAX 解析器
//            XMLInputFactory factory = XMLInputFactory.newInstance();
//            XMLStreamReader reader = factory.createXMLStreamReader(new FileInputStream("D:\\data\\upload\\amazonreport\\salestraffic\\asdsad\\salestraffic_report_4144\\salestraffic_report_4144.xml"));
//
//            // 2. 遍历 XML 事件
//            while (reader.hasNext()) {
//                int event = reader.next();
//                if (event == XMLStreamReader.START_ELEMENT) {
//                    String elementName = reader.getLocalName();
//                    if (elementName.equals("Node")) {
//                        System.out.println("Node: " );
//                    } else if (elementName.equals("browseNodeId")) {
//                        System.out.println("browseNodeId: " + reader.getElementText());
//                    } else if (elementName.equals("browseNodeAttributes")) {
//                        System.out.println("browseNodeAttributes: " + reader.getElementText());
//                    } else if (elementName.equals("attribute")) {
//                        System.out.println("attribute: " + reader.getElementText());
//                    } else if (elementName.equals("browseNodeName")) {
//                         System.out.println("browseNodeName: " + reader.getElementText());
//                    } else if (elementName.equals("browseNodeStoreContextName")) {
//                         System.out.println("browseNodeStoreContextName: " + reader.getElementText());
//                    } else if (elementName.equals("browsePathById")) {
//                         System.out.println("browsePathById: " + reader.getElementText());
//                    } else if (elementName.equals("browsePathByName")) {
//                         System.out.println("browsePathByName: " + reader.getElementText());
//                    } else if (elementName.equals("hasChildren")) {
//                         System.out.println("hasChildren: " + reader.getElementText());
//                    } else if (elementName.equals("childNodes")) {
//                         System.out.println("childNodes: " + reader.getElementText());
//                    } else if (elementName.equals("productTypeDefinitions")) {
//                         System.out.println("productTypeDefinitions: " + reader.getElementText());
//                    } else if (elementName.equals("refinementsInformation")) {
//                         System.out.println("refinementsInformation: " + reader.getElementText());
//                    }
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        try {
            // 1. 创建 DocumentBuilderFactory
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();

            // 2. 解析 XML 文件（假设文件名为 example.xml）
            Document document = builder.parse("D:\\data\\upload\\amazonreport\\salestraffic\\asdsad\\salestraffic_report_4144\\salestraffic_report_4144.xml");

            // 3. 获取根节点
            Element root = document.getDocumentElement();
            System.out.println("Root element: " + root.getNodeName());

            // 4. 遍历子节点
            NodeList nodeList = root.getElementsByTagName("Node");
            for (int i = 0; i < nodeList.getLength(); i++) {
                Element element = (Element) nodeList.item(i);
                String browseNodeId = element.getElementsByTagName("browseNodeId").item(0).getTextContent();
                String browseNodeAttributes = element.getElementsByTagName("browseNodeAttributes").item(0).getTextContent();
                String browseNodeName = element.getElementsByTagName("browseNodeName").item(0).getTextContent();
                String browseNodeStoreContextName = element.getElementsByTagName("browseNodeStoreContextName").item(0).getTextContent();
                String browsePathById = element.getElementsByTagName("browsePathById").item(0).getTextContent();
                String browsePathByName = element.getElementsByTagName("browsePathByName").item(0).getTextContent();
                String hasChildren = element.getElementsByTagName("hasChildren").item(0).getTextContent();
                String childNodes = element.getElementsByTagName("childNodes").item(0).getTextContent();
                NodeList childNodesNodeList = element.getElementsByTagName("childNodes");
                List<String> list = new ArrayList<>();
                if (hasChildren.equals("true")){
                    Element element11 = (Element)childNodesNodeList.item(0);
                    NodeList idList = element11.getElementsByTagName("id");
                    for (int j = 0; j < idList.getLength(); j++) {
                        String id = element11.getElementsByTagName("id").item(j).getTextContent();
                        list.add(id);
                    }
                }
                String childNodesNew = null;
                if (hasChildren.equals("true")){
                    childNodesNew = String.join(",", list);
                }
                String productTypeDefinitions = element.getElementsByTagName("productTypeDefinitions").item(0).getTextContent();
                String refinementsInformation = element.getElementsByTagName("refinementsInformation").item(0).getTextContent();

                System.out.println("---------------------新的一页--------------------");
                System.out.println("browseNodeId: " + browseNodeId + ", browseNodeAttributes: " + browseNodeAttributes);
                System.out.println("browseNodeName: " + browseNodeName + ", browseNodeStoreContextName: " + browseNodeStoreContextName);
                System.out.println("browsePathById: " + browsePathById + ", browsePathByName: " + browsePathByName);
                System.out.println("hasChildren: " + hasChildren + ", childNodes: " + childNodes + ", childNodesNew: " + childNodesNew );
                System.out.println("productTypeDefinitions: " + productTypeDefinitions + ", refinementsInformation: " + refinementsInformation);
                TbAmazonCategory tbAmazonCategory = TbAmazonCategory.tbAmazonCategory("GB",Long.parseLong(browseNodeId),browseNodeAttributes,browseNodeName,
                        browseNodeStoreContextName,browsePathById,browsePathByName,hasChildren,childNodesNew,productTypeDefinitions,refinementsInformation,1);
                tbAmazonCategoryMapper.insert(tbAmazonCategory);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 解析jsonSchema文件
     */
    @RequestMapping("/test711")
    @ResponseBody
    public void test711() {
//        try {
////            String schemaData = new String(Files.readAllBytes(Paths.get("C://Users//Administrator//Desktop//逸思1.0工作安排//亚马逊api文件//listing刊登//TOILET_PAPER-schema模板.txt")), StandardCharsets.UTF_8);
////            String inpuData = "{}";
////            JsonMetaSchema metaSchema = JsonMetaSchema.builder("https://schemas.amazon.com/selling-partners/definitions/product-types/meta-schema/v1", JsonMetaSchema.getV201909())
////                    .build();
////
////            JsonSchemaFactory factory = JsonSchemaFactory.builder()
////                    .defaultMetaSchemaIri(metaSchema.getIri()).metaSchema(metaSchema).build();
////            JsonSchema schema = factory.getSchema(schemaData);
////            List<ValidationMessage> messages = schema.validate(inpuData, InputFormat.JSON).stream().collect(Collectors.toList());
////            messages.forEach(a -> {
////                System.out.println(a.getProperty());
////            });
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }
}
